package com.jackrain.clouddata.sys.controller;
/**
 * Created by tangzhipeng on 2017/8/9
 */

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jackrain.nea.web.query.QueryEngine;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@Slf4j
/**
 * 获取sql配置表数据和执行时间表
 */
public class SqlConfigController {

    @RequestMapping(path = "/p/c/queryconfig", method = RequestMethod.POST)
    public JSONObject querySqlConfig(HttpServletRequest request) {
        String client_name = request.getParameter("CLIENT_NAME");
        log.info("------------------"+client_name+"------------------");
        JSONObject jo = new JSONObject();
        if (client_name==null) {
            jo.put("code", -1);
            jo.put("omssql", "");
            jo.put("omstime", "");
            return jo;
        }
        JSONArray sqlConfigJo = QueryEngine.getInstance().doQueryObjectArray("select t.TOPIC,s.SQL_VALUE,a.TAGNAME from OMS_SQL s,OMS_TOPIC t,OMS_TAG a" +
                " where s.TOPICID=t.ID and s.OMSTAGID=a.ID and a.TAGNAME = ?", new Object[]{client_name});
        JSONArray executeTimeJo = QueryEngine.getInstance().doQueryObjectArray("select t.TOPIC,s.STARTTIME,s.EXESTEPTIME,a.TAGNAME from OMS_TOPICTIME s,OMS_TOPIC t,OMS_TAG a" +
                " where s.OMS_TOPICID=t.ID and s.OMSTAGID=a.ID and a.TAGNAME = ?", new Object[]{client_name});
        log.info("---------------------" + sqlConfigJo + "----------------------");
        log.info("---------------------" + executeTimeJo + "----------------------");
        jo.put("code", 0);
        jo.put("omssql", sqlConfigJo);
        jo.put("omstime", executeTimeJo);
        return jo;
    }
}
